package swingExtended.swingControlGroup;

import java.io.IOException;
import javax.swing.JCheckBox;
import javax.swing.JTextField;

/**
 *
 * @author g1wshimu
 * Created: Nov 14, 2013
 */
public class SwingControlMap extends BindableControlMap {

    public SwingControlMap() {
    }

    public BindableControl put(String key, final JTextField component) {
        return super.put(key, new BindableControl(){

            @Override
            public Object getBindedValue() {
                return component.getText();
            }

            @Override
            public void setText(Object value) {
                component.setText(value.toString());
            }
        });
    }

    public BindableControl put(String key, final JCheckBox checkBox) {
        return super.put(key, new BindableControl(){

            @Override
            public Object getBindedValue() {
                return checkBox.isSelected();
            }

            @Override
            public void setText(Object value) {                
                checkBox.setSelected(Boolean.parseBoolean(value.toString()));
            }
        });
    }
    
    public void load(String url) throws IOException {
        loadFromMapping(UnusedIO.load(url));
    }
}
